package cn.vcjf.washcar.common.web;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.plugins.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @Auther: zhengzihang
 * @Date: 2018/7/5 18:20
 * @Description:
 */
public class PageModel<T> implements Serializable {

	private static final long serialVersionUID = 12L;
	@TableField(exist=false)
	private Integer page;

	@TableField(exist=false)
	private Integer limit;

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField(exist=false)
	private Date begDate;

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField(exist=false)
	protected Date endDate;
	/**
	 * 创建人
	 */
	protected String createUser;

	/**
	 * 创建时间
	 */
	protected Date createTime;

	/**
	 * 修改人
	 */
	protected String updateUser;

	/**
	 * 修改时间
	 */
	protected Date updateTime;

	/**
	 * 删除标记
	 */
	@TableLogic
	protected Integer deleteFlag;

	/**
	 * 构造分页实体类
	 * @return  分页对象
	 */
	@JsonIgnore
	public Page<T> getPageInfo(){
		return new Page<T>(this.getPage(), this.getLimit());
	}
	@JsonIgnore
	public Integer getPage() {
		if(page==null||page<=0){
			page=1;
		}
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}
	@JsonIgnore
	public Integer getLimit() {
		if (limit == null){
			limit=1000;
		}
		if(limit<=0){
			limit=10;
		}
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}
	@JsonIgnore
	public Date getBegDate() {
		return begDate;
	}

	public void setBegDate(Date begDate) {
		this.begDate = begDate;
	}
	@JsonIgnore
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	@JsonIgnore
	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}
	@JsonIgnore
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	@JsonIgnore
	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}
	@JsonIgnore
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	@JsonIgnore
	public Integer getDeleteFlag() {
		return deleteFlag;
	}

	public void setDeleteFlag(Integer deleteFlag) {
		this.deleteFlag = deleteFlag;
	}

	public void preInsert(){
		this.setCreateUser("admin");
		this.setCreateTime(new Date());
	}
	public void preUpdate(){
		this.setCreateUser("admin");
		this.setUpdateTime(new Date());
	}
}
